const path = require('path')
const webpack = require('webpack')
const HtmlPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const babelConfig = require('./babel.config')
module.exports = {
    entry: './src/main.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname,'dist')
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: 'vue-loader',
            },
            {
                test: /\.js$/,
                use: {
                    loader: 'babel-loader',
                    options:babelConfig
                },
                enforce: 'post',
                exclude: /node_module/
            },
            {
                test: /\.(js|vue)$/,
                use: {
                    loader: 'eslint-loader',
                    options:{
                        formatter: require("eslint-friendly-formatter")
                    }
                },
                enforce: 'pre',
                include: [path.resolve(__dirname, 'src')]
            },
            {
                test: /\.css$/,
                use: ['vue-style-loader', 'css-loader'],
            },
            {
                test: /\.less$/,
                use: ['css-loader', 'less-loader']
            },
            {
                test: /\.png$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10*1024,
                        esModule: false
                    }
                },
            }
        ]
    },
    plugins: [
        new HtmlPlugin({
            title: 'lamack-vue',
            template: './public/index.html',
            filename: 'index.html'
        }),
        new webpack.DefinePlugin({
            BASE_URL: '"./"'
        }),
        new VueLoaderPlugin(),
        new CleanWebpackPlugin()
    ]

}